package com.qyl.honghengshop.utils;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

import org.springframework.web.multipart.MultipartFile;

public class FileUpload {

	public static String fileUpload(MultipartFile shopPic) throws Exception{
		
		//获得服务器路径
		String serverPath = "d:/img";
		//获得上传文件名
		String fileName = shopPic.getOriginalFilename();
		//获得后缀名
		String extName = fileName.substring(fileName.lastIndexOf("."));
		//生成uuid
		String uuid = UUID.randomUUID().toString();
		//创建保存文件路径
		File file = new File(serverPath+"/upload/"+uuid+extName);

		if(!file.exists()){
			file.mkdirs();
		}
		//转存到保存路径
		shopPic.transferTo(file);
		
		return uuid+extName;
	}
	
}
